﻿namespace SampleApplication.CoffeeShopSample.Implementation.Domain
{
    #region Usings

    using Dependencies.Domain;
    using System;

    #endregion Usings

    public class CoffeeShop : ICoffeeShop
    {
        private readonly ICoffeeMachine coffeeMachine;
        private readonly ICoffeeDispenser coffeeDispenser;
        private readonly ITeaMachine teaMachine;
        private readonly ICupFactory cupFactory;

        public CoffeeShop(ICoffeeMachine coffeeMachine,
            ICoffeeDispenser coffeeDispenser,
            ITeaMachine teaMachine,
            ICupFactory cupFactory)
        {
            if (coffeeMachine == null) throw new ArgumentNullException("coffeeMachine");
            if (coffeeDispenser == null) throw new ArgumentNullException("coffeeDispenser");
            if (teaMachine == null) throw new ArgumentNullException("teaMachine");
            if (cupFactory == null) throw new ArgumentNullException("cupFactory");

            this.coffeeMachine = coffeeMachine;
            this.coffeeDispenser = coffeeDispenser;
            this.teaMachine = teaMachine;
            this.cupFactory = cupFactory;
        }

        public ICup MakeCoffee()
        {
            var coffeeBeans = coffeeDispenser.GetCoffeeBeans();

            var coffee = coffeeMachine.MakeCoffee(coffeeBeans);

            return cupFactory.MakeCup(coffee);
        }

        public ICup MakeTea(ITeaBag teaBag)
        {
            return cupFactory.MakeCup(teaMachine.MakeTea(teaBag));
        }
    }
}